﻿Imports System.Math
Imports System.Text

Public Class frmToxicologia
    Inherits formPadrao

    Private Sep As Char


    Private Sub rbNao_CheckedChanged(sender As Object, e As EventArgs) Handles rbNao.CheckedChanged
        habilita(False)
        If rbNao.Checked Then
            lblMensagem.Text = "Não há necessidade de realizar a amostragem do material"
        End If
    End Sub

    Private Sub limpacampos()

        lblMensagem.Text = String.Empty
        rbNao.Checked = False
        rbSim.Checked = False
        cmbAcondicionamento.SelectedItem = -1
        cmbDescricao.SelectedIndex = -1
        cmdSubstancia.SelectedIndex = -1
        txtAcondicionamento.Text = String.Empty
        txtPesoTotal.Text = String.Empty
        txtQtdeUnidades.Text = String.Empty
        habilita(False)

    End Sub

    Private Sub habilita(ByVal habilita As Boolean)

        lbAut.Visible = habilita
        lbIc.Visible = habilita
        txtInvolucroIC.Visible = habilita
        txtInvolucroAut.Visible = habilita

        If Not habilita Then
            cmbAcondicionamento.SelectedIndex = -1
            txtInvolucroAut.Text = String.Empty
            txtInvolucroIC.Text = String.Empty
        End If

    End Sub


    Private Sub cmbAcondicionamento_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cmbAcondicionamento.SelectedIndexChanged
        '   habilita(False)

        If Not IsNothing(cmbAcondicionamento.SelectedItem) Then


            If cmbAcondicionamento.SelectedItem.ToString.ToLower.ToString.Equals("invólucro de segurança") Then

                If rbNao.Checked Then
                    lbIc.Visible = True
                    txtInvolucroIC.Visible = True

                ElseIf rbSim.Checked Then
                    lbIc.Visible = True
                    txtInvolucroIC.Visible = True
                    txtInvolucroAut.Visible = True
                    txtInvolucroIC.Visible = True
                End If

            Else
                lbIc.Visible = False
                txtInvolucroIC.Visible = False
                txtInvolucroAut.Visible = False
                txtInvolucroIC.Visible = False
            End If

        End If
    End Sub

    Private Sub frmToxicologia_Load(sender As Object, e As EventArgs) Handles Me.Load
        Try
            Me.WindowState = FormWindowState.Maximized
            limpacampos()

        Catch ex As Exception
            generica.gravaErro(ex)

        End Try
    End Sub
    Private Sub rbSim_CheckedChanged(sender As Object, e As EventArgs) Handles rbSim.CheckedChanged
        habilita(False)
        If rbSim.Checked Then

            Dim n As Integer

            n = Sqrt(txtQtdeUnidades.Text)

            lblMensagem.Text = "Retirar : " & n & " amostras da substância"

        End If
    End Sub

   
    Private Sub cmbAdicionar_Click(sender As Object, e As EventArgs) Handles cmbAdicionar.Click

        Dim txtMaterial As New StringBuilder
        Dim count As Integer = gridDrogas.Rows.Count

        Try
            txtMaterial.Append("Material ").Append(generica.formataNumeroMaterial(count + 1)).Append(":")
            txtMaterial.Append(txtQtdeUnidades.Text).Append("(").Append(generica.NumeroToExtenso(CInt(txtQtdeUnidades.Text))).Append(")")
            txtMaterial.Append(txtAcondicionamento.Text).Append("...etc,etc...")
            gridDrogas.Rows.Add(txtMaterial.ToString)
            limpacampos()
        Catch ex As Exception

            MsgBox("Ocorreu o seguinte erro:" & ex.InnerException.StackTrace & "erro:" & ex.Message)
        End Try
    End Sub

  
    Private Sub gridDrogas_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles gridDrogas.CellContentClick
        If (e.ColumnIndex = gridDrogas.Columns("DELETE").Index And e.RowIndex >= 0) Then

            gridDrogas.Rows.Remove(gridDrogas.Rows(e.RowIndex))

        End If
    End Sub

    Private Sub txtQtdeUnidades_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtQtdeUnidades.KeyPress
        If Not (Char.IsNumber(e.KeyChar) Or Char.IsControl(e.KeyChar)) Then e.Handled = True
    End Sub

    Private Sub txtInvolucroIC_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtInvolucroIC.KeyPress
        If Not (Char.IsNumber(e.KeyChar) Or Char.IsControl(e.KeyChar)) Then e.Handled = True
    End Sub


    Private Sub txtInvolucroAut_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtInvolucroAut.KeyPress
        If Not (Char.IsNumber(e.KeyChar) Or Char.IsControl(e.KeyChar)) Then e.Handled = True
    End Sub

 

    Private Sub cmbGerar_Click(sender As Object, e As EventArgs) Handles cmbGerar.Click
        MsgBox("A ser implementado após definição Química Legal")
    End Sub

   

    'Private Sub txtPesoTotal_KeyPress1(sender As Object, e As KeyPressEventArgs) Handles txtPesoTotal.KeyPress
    ''    If Not (Char.IsNumber(e.KeyChar) Or e.KeyChar.Equals(Sep) Or Char.IsControl(e.KeyChar)) Then

    ''        e.Handled = True
    ''    End If

    'End Sub


    Private Sub txtPesoTotal_TextChanged(sender As Object, e As EventArgs) Handles txtPesoTotal.TextChanged

    End Sub

    Private Sub txtQtdeUnidades_MaskInputRejected(sender As Object, e As MaskInputRejectedEventArgs) Handles txtQtdeUnidades.MaskInputRejected

    End Sub
End Class